#include "studycomponent.h"
#include "ui_studycomponent.h"

#include <QDebug>
StudyComponent::StudyComponent(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::StudyComponent)
{
    ui->setupUi(this);

    // QPushButton
    connect(ui->pushButton, &QPushButton::clicked, this, []()
    {
       qDebug() << "PushButoon is clicked...";
    });

    // QLabel
    ui->label->setText("I am QLabel");

    // QLineEdit
    ui->lineEdit->setText("I am QLineEdit");

    // QRadioButton
    connect(ui->radioButton, &QRadioButton::clicked, this, [=](bool checked)
    {
        if(checked)
        {
            qDebug() << "RadioButton is selected...";
        }
        else
        {
            qDebug() << "RadioButton is unSelected...";
        }
    });

    // QCheckBox
    connect(ui->checkBox, &QCheckBox::stateChanged, this, [this](int state)
    {
        qDebug() << state;
        qDebug() << ui->checkBox->checkState();
    });

    // QComboBox
    QStringList list;
    list.append("1");
    list.append("2");
    list.append("3");
    ui->comboBox->addItems(list);

    // QSlider
    ui->horSlider->setRange(0, 26);
    connect(ui->horSlider, &QSlider::valueChanged, this, [](int val)
    {
        qDebug() << "horSlider -- " << val;
    });

    ui->verSlider->setRange(26, 54);
    connect(ui->verSlider, &QSlider::valueChanged, this, [](int val)
    {
        qDebug() << "verSlider -- " << val;
    });

    // QProgressBar
    ui->progressBar->setRange(0, 100);
    ui->progressBar->setValue(50);

    // QListWidget
    ui->listWidget->addItem("111");
    ui->listWidget->addItem("222");
    ui->listWidget->addItem("333");

    // QTableWidget
    ui->tableWidget->setRowCount(2);
    ui->tableWidget->setColumnCount(6);
    QLabel* label = nullptr;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            label = new QLabel(QString("(%1, %2)").arg(i+1).arg(j+1), this);
            ui->tableWidget->setCellWidget(i, j, label);
        }
    }
}

StudyComponent::~StudyComponent()
{
    delete ui;
}
